var express = require('express')
var router = express.Router()

// 导入db，操作数据库
const { getAll, getById, exec } = require('../db')

/**
 * 获取各个分类下的文章信息
 */
router.get('/', async (req, res) => {
  let sql = `SELECT a.count as value,b.category_name as name from (SELECT category_id,COUNT(category_id) as count from bk_articles GROUP BY category_id) as a RIGHT JOIN bk_category as b on a.category_id = b.category_id`
  const data = await getAll(sql)
  res.send({
    code: 0,
    message: '获取分类下的文章信息成功',
    result: data,
  })
})

module.exports = router
